package com.atguigu;

import com.atguigu.bean.Person;
import com.atguigu.config.MainConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 *
 * 注册时类
 * @author : zjj
 * @date : 2021/9/17 15:40
 */
public class MainTest {


    public static void main(String[] args) {
//        testBeanAndConfiguration();
        testComponentScan();
    }

    public static void testComponentScan(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfiguration.class);
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames
             ) {
            System.out.println("beanName : " +  beanName);
        }
    }

    /**
     * 测试  @Bean 注解  和 @Configuration注解
     */
    public static void testBeanAndConfiguration(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfiguration.class);

        Person bean = applicationContext.getBean(Person.class);

        String[] beanNamesForType = applicationContext.getBeanNamesForType(Person.class);

        for (String beanName : beanNamesForType) {
            System.out.println("bean 名称：" + beanName);

        }
    }
}
